<template>
  <div>
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['system:role:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['system:role:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['system:role:export']"
        >导出</el-button>
      </el-col>
    </el-row>


    <el-table  :data="arr"  style="width: 100%">
      <el-table-column  label="编号"  width="100">
        <template slot-scope="scope">
          <span style="margin-left: 10px">{{ scope.row.id }}</span>
        </template>
      </el-table-column>

      <el-table-column  label="分类名称"  width="100">
        <template slot-scope="scope">
          <span style="margin-left: 10px">{{ scope.row.classifyName }}</span>
        </template>
      </el-table-column>

      <el-table-column  label="级别"  width="100">
        <template slot-scope="scope">
          <span style="margin-left: 10px" v-if="scope.row.classifyLevel==1">一级</span>
          <span style="margin-left: 10px" v-if="scope.row.classifyLevel==2">二级</span>
        </template>
      </el-table-column>

      <el-table-column  label="商品数量"  width="100">
        <template slot-scope="scope">
          <span style="margin-left: 10px">{{ scope.row.classifyNumber }}</span>
        </template>
      </el-table-column>

      <el-table-column  label="数量单位"  width="100">
        <template slot-scope="scope">
          <span style="margin-left: 10px">{{ scope.row.classifyUnit }}</span>
        </template>
      </el-table-column>

      <el-table-column  label="导航栏"  width="100">
        <template slot-scope="scope">
          <el-switch v-model="value" active-color="#13ce66" inactive-color="#ff4949">
            <span style="margin-left: 10px" v-if="scope.row.brandManufacturer==0"></span>
          </el-switch>
        </template>
      </el-table-column>


      <el-table-column  label="是否显示"  width="100">
        <template slot-scope="scope">
          <el-switch v-model="value1" active-color="#13ce66" inactive-color="#ff4949">
            <span style="margin-left: 10px" v-if="scope.row.isShow==0"></span>
          </el-switch>
        </template>
      </el-table-column>


      <el-table-column label="设置">
        <template slot-scope="scope">
          <el-button size="mini"  @click="handleSelectNext(scope.row.id)">查看下级</el-button>
          <el-button size="mini" type="danger" @click="handleMoveShop(scope.row)">转移商品</el-button>
        </template>
      </el-table-column>

      <el-table-column label="操作">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['system:role:remove']"
          >删除</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
          >修改</el-button>
        </template>
      </el-table-column>
    </el-table>



    <!-- 添加或修改角色配置对话框 -->
    <el-dialog :title="title" :visible.sync="openn" width="500px" append-to-body>
      <el-form ref="form" :model="form" label-width="100px">
        <el-form-item label="分类名称" prop="classifyName">
          <el-input v-model="form.classifyName" />
        </el-form-item>
        <el-form-item label="分类级别" prop="classifyLevel">
          <el-input v-model="form.classifyLevel" />
        </el-form-item>
        <el-form-item label="数量" prop="classifyNumber">
          <el-input v-model="form.classifyNumber" />
        </el-form-item>
        <el-form-item label="数量单位" prop="classifyUnit">
          <el-input v-model="form.classifyUnit" />
        </el-form-item>
        <el-form-item label="导航栏">
          <el-radio v-model="form.classifyNavigation" :label="0">是</el-radio>
          <el-radio v-model="form.classifyNavigation" :label="1">否</el-radio>
        </el-form-item>
        <el-form-item label="是否展示">
          <el-radio v-model="form.isShow" :label="0">是</el-radio>
          <el-radio v-model="form.isShow" :label="1">否</el-radio>
        </el-form-item>

        <el-form-item label="父级ID" prop="parentId">
          <el-input v-model="form.parentId" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
      </div>
    </el-dialog>


  </div>

</template>

<script>
import {addClassify, delClassify, findBy, updateClassify} from "@/api/product/classify";
import {addBrand, delBrand, updateBrand} from "@/api/product/brand";

export default {
  name: 'Brand',
  dicts: ['sys_normal_disable'],
  data(){
    return {
      shopClassify:{
        parentId:0
      },
      arr:[],
      value: true,
      value1:true,
      form:{},
      title: "",
      // 显示搜索条件
      showSearch: true,
      openn:false
    }
  },
  methods: {
    /** 新增按钮操作 */
    handleAdd() {
      this.openn = true;
      this.title = "添加品牌";

    },
    findBy(){
      findBy(this.shopClassify.parentId).then(res=>{
        this.arr=res.data
        console.log(this.arr)
      })
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.form=row;
      this.openn=true;
    },
    handleSelectNext(id) {
      findBy(id).then(res=>{
        this.arr=res.data
      })
    },
    handleMoveShop(row) {
      console.log(row);
    },
    /** 提交按钮 */
    submitForm() {
      console.log(this.form)
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateClassify(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.openn = false;
              this.findBy();
            });
          } else {
            addClassify(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.openn = false;
              this.findBy();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除分类编号为"' + ids + '"的数据项？').then(function() {
        return delClassify(ids);
      }).then(() => {
        this.findBy();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },

  },
  created() {
    this.findBy()
  }
}

</script>

<style scoped lang="scss">

</style>
